home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 7.9 KB | 281 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWFontLi.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWFONTLI_H
- #include "FWFontLi.h"
- #endif
-
- #ifndef FWINTSTR_H
- #include "FWIntStr.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- // ----- Platform Includes -----
-
- #ifdef FW_BUILD_WIN
- #include <windows.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__MENUS__)
- #include <Menus.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__SCRIPT__)
- #include <Script.h>
- #endif
-
- //========================================================================================
- // Runtime infos
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphx_FontList
- #endif
-
- //========================================================================================
- // CLASS FW_CFontList
- //========================================================================================
-
- FW_DEFINE_CLASS_M0(FW_CFontList)
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // PrivWinFillFontList
- //
- // Windows callback method to insert font names into the supplied list.
- //----------------------------------------------------------------------------------------
-
- static int CALLBACK PrivWinFillFontList(const LOGFONT* lplf,
- const TEXTMETRIC* /* lptm */,
- DWORD /* dwFontType */,
- LPARAM lParam)
- {
- FW_CPrivOrderedCollection* pList = (FW_CPrivOrderedCollection *)lParam;
-
- // Find the face name of the font.
- FW_Char* FaceName = (FW_Char *) lplf->lfFaceName;
-
- // Add it to the list.
- FW_CIntlString* fontName = new FW_CIntlString(FaceName);
- pList->AddLast(fontName);
-
- return TRUE; // Keep going
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CFontList::FW_CFontList
- //----------------------------------------------------------------------------------------
-
- FW_CFontList::FW_CFontList()
- {
- #ifdef FW_BUILD_MAC
- const short dummyMenuID = 7777;
- MenuHandle fontListHolder = ::NewMenu(dummyMenuID, "\pODF");
-
- if (fontListHolder == NULL)
- FW_Failure(FW_xMemoryExhausted);
-
- short count = 0;
-
- FW_TRY
- {
- ::AppendResMenu(fontListHolder, 'FONT');
- count = ::CountMItems(fontListHolder);
- Str255 itemName;
-
- // get System script code and language code
- long systemScriptCode = ::GetScriptManagerVariable(smSysScript);
- long systemLanguageCode = ::GetScriptVariable(systemScriptCode, smScriptLang);
- short itemField;
-
- for (short k = 1; k <= count; k++)
- {
- ::GetMenuItemText(fontListHolder, k, itemName);
- ::GetItemCmd(fontListHolder, k, &itemField); // Check cmd key equivalent code
-
- ODScriptCode scriptCode = (ODScriptCode) systemScriptCode;
- ODLangCode languageCode = (ODLangCode) systemLanguageCode;
-
- if (itemField == 0x1C)
- // key equiv value of 0x1C indicates that the icon field contains a script code
- {
- ::GetItemIcon(fontListHolder, k, &itemField); // get script code from icon field
- scriptCode = (ODScriptCode) itemField;
- if (itemField == 0x00FF) /* kludge */
- scriptCode = (ODScriptCode) systemScriptCode;
- // Get the language code from the script code
- languageCode = (ODLangCode) ::GetScriptVariable(scriptCode, smScriptLang);
- }
-
- FW_CIntlString* fontName = FW_NEW(FW_CIntlString,
- ((const FW_Char *) &itemName[1],
- (FW_CharacterCount) itemName[0],
- scriptCode, languageCode));
- fFontList.AddLast(fontName);
- }
- ::DisposeMenu(fontListHolder);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- ::DisposeMenu(fontListHolder);
- FW_THROW_SAME();
- }
- FW_CATCH_END
- #endif
-
- #ifdef FW_BUILD_WIN
- HDC dc = ::GetDC(NULL);
- if(dc != 0)
- {
- FW_TRY
- {
- ::EnumFontFamilies(dc, NULL, ::PrivWinFillFontList, (LPARAM) &fFontList);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- ::ReleaseDC(NULL, dc);
- FW_THROW_SAME();
- }
- FW_CATCH_END
- ::ReleaseDC(NULL, dc);
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontList::~FW_CFontList
- //----------------------------------------------------------------------------------------
-
- FW_CFontList::~FW_CFontList()
- {
- FW_COrderedCollectionIterator ite(&fFontList);
- for (FW_CIntlString* fontName = (FW_CIntlString *) ite.First();
- ite.IsNotComplete();
- fontName = (FW_CIntlString *) ite.Next())
- {
- delete fontName;
- }
- }
-
- //========================================================================================
- // CLASS FW_CFontIterator
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::FW_CFontIterator
- //----------------------------------------------------------------------------------------
-
- FW_CFontIterator::FW_CFontIterator() :
- fFontList(NULL),
- fDeleteTheList(TRUE),
- fIterator(NULL)
- {
- fFontList = FW_NEW(FW_CFontList, ());
- fIterator = new FW_COrderedCollectionIterator(&fFontList->fFontList);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::FW_CFontIterator
- //----------------------------------------------------------------------------------------
-
- FW_CFontIterator::FW_CFontIterator(FW_CFontList* fontList) :
- fFontList(fontList),
- fDeleteTheList(FALSE),
- fIterator(NULL)
- {
- FW_ASSERT(fontList != NULL);
-
- fIterator = new FW_COrderedCollectionIterator(&fFontList->fFontList);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::~FW_CFontIterator
- //----------------------------------------------------------------------------------------
-
- FW_CFontIterator::~FW_CFontIterator()
- {
- FW_START_DESTRUCTOR
-
- if (fDeleteTheList)
- delete fFontList;
-
- delete fIterator;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::First
- //----------------------------------------------------------------------------------------
-
- FW_CIntlString FW_CFontIterator::First()
- {
- FW_CIntlString *name = (FW_CIntlString *) fIterator->First();
- return name ? *name : FW_CIntlString("");
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::Next
- //----------------------------------------------------------------------------------------
-
- FW_CIntlString FW_CFontIterator::Next()
- {
- FW_CIntlString *name = (FW_CIntlString *) fIterator->Next();
- return name ? *name : FW_CIntlString("");
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::Last
- //----------------------------------------------------------------------------------------
-
- FW_CIntlString FW_CFontIterator::Last()
- {
- FW_CIntlString *name = (FW_CIntlString *) fIterator->Last();
- return name ? *name : FW_CIntlString("");
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::Previous
- //----------------------------------------------------------------------------------------
-
- FW_CIntlString FW_CFontIterator::Previous()
- {
- FW_CIntlString *name = (FW_CIntlString *) fIterator->Previous();
- return name ? *name : FW_CIntlString("");
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::IsNotComplete
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CFontIterator::IsNotComplete()
- {
- return fIterator->IsNotComplete();
- }
-